/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.Facturacion;

import java.awt.BorderLayout;
import java.util.ArrayList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

/**
 *
 * @author dianacha
 */
public class TablaFacturacion extends JPanel{
        
    private final ModeloTablaFact modelTable;
    private final JTable table;
    
    public TablaFacturacion(ArrayList<String> colNames){
               
        modelTable = new ModeloTablaFact(colNames);
        table = new JTable(modelTable);
        
        organizar();
    }
    
    private void organizar(){
        JScrollPane scrollTabla = new JScrollPane(table);
        
        this.setLayout(new BorderLayout());
        this.add(scrollTabla, BorderLayout.CENTER);
    }
    
    public void agregarFila(ArrayList<String> pn){
        
        int size = modelTable.getColumnCount();
        Object[] rowNew = new Object[size];
        //"Cod. Producto", "Nombre", "Precio Unidad", "Cantidad", "Subtotal"
        
        for(int i=0;i<size;i++){
            rowNew[i]= "";//
            if(i==0){
                rowNew[i]=Integer.parseInt(pn.get(0));
            }
            if(i==3){
                rowNew[i]=pn.get(1);
            }
        }
        
        modelTable.addRow(rowNew);
    }
    
    public void limpiarTable(){
        modelTable.clearRows();
    }
}
